home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Networking / SNMP / SNMP Development / MacSNMP Developer 1.0.2 / Library Manager Interfaces / LibraryManagerUtilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  11.2 KB  |  346 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        LibraryManagerUtilities.h
  3.  
  4.     Contains:    Interfaces file for LibraryManager utilities
  5.  
  6.     Copyright:    © 1991-1992 by Apple Computer, Inc., all rights reserved.
  7.  
  8. */
  9.  
  10.  
  11. #ifndef __LIBRARYMANAGERUTILITIES__
  12. #define __LIBRARYMANAGERUTILITIES__
  13.  
  14. #ifndef __LIBRARYMANAGER__
  15. #include <LibraryManager.h>
  16. #endif
  17.  
  18. /**********************************************************************
  19. ** Typedefs
  20. ***********************************************************************/
  21.  
  22. #ifndef MACOS
  23. typedef Ptr*                    Handle;
  24. typedef    unsigned long            ResType;
  25. typedef const unsigned char*    ConstStr255Param;
  26. #endif
  27.  
  28. /**********************************************************************
  29. ** Routines for loading and unloading the LibraryManager.
  30. **
  31. ** UnloadLibraryManager and LoadLibraryManager can be bad for your health! 
  32. ** They should only be used for testing purposes.
  33. ***********************************************************************/
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. Boolean    IsLibraryManagerLoaded();
  40. Boolean    LoadLibraryManager();        // returns true if successful or already loaded
  41. void    UnloadLibraryManager();
  42.  
  43. /**********************************************************************
  44. ** GetSLMVersion
  45. **
  46. ** Returns the version of the installed LibraryManager in the 'vers'
  47. ** resource format (the first 4 bytes only). Returns 0 if the
  48. ** LibraryManager is not installed.
  49. ***********************************************************************/
  50.  
  51. unsigned long GetSLMVersion();
  52.  
  53. /**********************************************************************
  54. ** RegisterInspector
  55. **
  56. ** Should only be used by Inspector application.
  57. ***********************************************************************/
  58.  
  59. void RegisterInspector(void*);
  60.  
  61. /**********************************************************************
  62. ** Trace
  63. **
  64. ** Used to send output to the Inspector's Trace Window.
  65. ***********************************************************************/
  66.  
  67. void Trace(const char *formatStr, ...);
  68.  
  69. /**********************************************************************
  70. ** SLMsprintf
  71. **
  72. ** The SLMsprintf routine in stdclib.o won't work with LibraryManager libraries.
  73. ** Use the one in LibraryManager.o instead.
  74. ***********************************************************************/
  75.  
  76. int    SLMsprintf(char *outString, const char *argp, ...);                
  77.  
  78. /**********************************************************************
  79. ** Utility functions for getting high and low bytes and words
  80. ***********************************************************************/
  81.  
  82. #ifdef __cplusplus
  83.  
  84. inline unsigned short HighWord(unsigned long l)
  85. {
  86.     return (unsigned short)((l >> 16) & 0xffff);
  87. }
  88.  
  89. inline unsigned short LowWord(unsigned long l)
  90. {
  91.     return (unsigned short)(l & 0xffff);
  92. }
  93.  
  94. inline unsigned char HighByte(unsigned short l)
  95. {
  96.     return (unsigned char)((l >> 8) & 0xff);
  97. }
  98.  
  99. inline unsigned char LowByte(unsigned short l)
  100. {
  101.     return (unsigned char)(l & 0xff);
  102. }
  103.  
  104. #else
  105.  
  106. #define HighWord(x)        ((unsigned short)(((x) >> 16) & 0xffff))
  107. #define LowWord(x)        ((unsigned short)((x) & 0xffff))
  108. #define HighByte(x)        ((unsigned char)(((x) >> 8) & 0xff))
  109. #define LowByte(x)        ((unsigned char)((x) & 0xff))
  110.  
  111. #endif
  112.  
  113. /*******************************************************************************
  114. ** Atomic Bit functions
  115. **
  116. ** These functions atomically set and clear bits, and return what value the
  117. ** bit previously had
  118. ********************************************************************************/
  119.  
  120. Boolean        SetBit(void* mem, size_t bitno);
  121. Boolean        ClrBit(void* mem, size_t bitno);
  122. Boolean        TstBit(const void* mem, size_t bitno);
  123.  
  124. /**********************************************************************
  125. ** Memory Functions
  126. **
  127. ** memcpy and memmove are declared in String.h, but we also declare them
  128. ** here just to let you know that the LibraryManager provides its own 
  129. ** implementationin LibraryManager.o.
  130. ***********************************************************************/
  131.  
  132. void    ZeroMem(void* destPtr, size_t byteCount);
  133. void*    memcpy(void* destPtr, void* srcPtr, size_t byteCount);
  134. void*    memmove(void* destPtr, void* srcPtr, size_t byteCount);
  135.  
  136. /*******************************************************************************
  137. ** EnterSystemMode/LeaveSystemMode
  138. **
  139. ** These functions should bracket calls that open files or get memory that needs
  140. ** to hang around after an application quits
  141. ********************************************************************************/
  142.  
  143. void*    EnterSystemMode();
  144. void    LeaveSystemMode(void*);
  145.  
  146. /*******************************************************************************
  147. ** Exception Handling
  148. **
  149. ** This stuff is only needed by the exception handling macros. Don't use directly!
  150. ********************************************************************************/
  151.  
  152. #ifdef __cplusplus
  153. class    TException;
  154. #else
  155. typedef void TException;
  156. #endif
  157.  
  158. void PushExceptionHandler(TException*);
  159. TException* PopExceptionHandler();
  160.  
  161.  
  162. /*******************************************************************************
  163. ** EnterInterrupt/LeaveInterrupt
  164. **
  165. ** These functions should be called when you are in an interrupt service routine
  166. ** or a deferred task and you want to do something that will cause LibraryManager
  167. ** code to be executed such as allocating pool memory or newing an object. The
  168. ** LibraryManager needs to know that it is at interrupt time so it doesn't do
  169. ** anything stupid like try to allocate memory or load library code. This doesn't
  170. ** mean that all LibraryManager calls are safe at interrupt time, just that the
  171. ** ones that claim to be safe will only be safe if you do an EnterInterrupt call
  172. ** first.
  173. **
  174. ** You don't need to use these routines when your interrupt service routine is
  175. ** scheduling an operation on a TInterruptScheduler, when the operation gets
  176. ** executed at deferred task time, or when a TTimeScheduler operation gets
  177. ** executed. In the former case the LibraryManager is smart enough to realize
  178. ** that you are at interrupt time and in the later two cases the
  179. ** LibraryManager does an EnterInterrupt before calling your operation and a
  180. ** LeaveInterrupt when your operation returns.
  181. ********************************************************************************/
  182.  
  183. void    EnterInterrupt();
  184. void    LeaveInterrupt();
  185.  
  186. /*******************************************************************************
  187. ** AtInterruptLevel
  188. **
  189. ** This function returns true if we are currently executing at non-system-task
  190. ** time.
  191. ********************************************************************************/
  192.  
  193. Boolean AtInterruptLevel();
  194.  
  195. /*******************************************************************************
  196. ** InInterruptScheduler
  197. **
  198. ** This function returns true if we are currently running an interrupt scheduler
  199. ********************************************************************************/
  200.  
  201. Boolean InInterruptScheduler();
  202.  
  203. /**********************************************************************
  204. ** GlobalWorld routines
  205. **
  206. ** InitGlobalWorld will create and initialize the global world for
  207. ** standalone code on the MacOS such as INITs and CDEVs. It also does
  208. ** a SetCurrentGlobalWorld. FreeGlobalWorld will free the memory used
  209. ** by the global world created by InitGlobalWorld.
  210. **
  211. ** SetCurrentGlobalWorld and GetCurrentGlobalWorld used for getting and
  212. ** setting A5 on the MacOS.
  213. **
  214. ** GetGlobalWorld is used to get the global world pointer for a Library.
  215. ** OpenGlobalWorld will make the library's global world the current global
  216. ** world. It's the same as calling SetCurrentGlobalWorld(GetGlobalWorld()).
  217. ** CloseGlobalWorld is used to revert back to the global world that was
  218. ** current before calling OpenGlobalWorld. It's the same as calling
  219. ** SetCurrentGlobalWorld(oldWorld) except that it doesn't return a
  220. ** global world.
  221. **
  222. ** Since libraries are always compiled with model far, it's
  223. ** not necessary to do an OpenGlobalWorld before accessing globals or
  224. ** making intersegment calls. Their only purpose is to make the library
  225. ** the current "Client" since the client is determined by the current
  226. ** value of A5 on the MacOS.
  227. **
  228. ** ONLY LIBRARIES AND MODEL FAR CLIENTS SHOULD CALL Get/Open/CloseGlobalWorld.
  229. ***********************************************************************/
  230.  
  231. typedef void*            GlobalWorld;
  232.  
  233. #ifndef kInvalidWorld
  234. #define kInvalidWorld        ((GlobalWorld)0)
  235. #endif
  236.  
  237. #pragma parameter __D0 SetCurrentGlobalWorld(__A0)
  238. GlobalWorld SetCurrentGlobalWorld(GlobalWorld newWorld)
  239.     = {0x200D,                        /* move.l    A5,D0        */
  240.        0x2A48};                        /* move.l    A0,A5        */
  241.        
  242. GlobalWorld GetCurrentGlobalWorld()
  243.     = {0x200D};                        /* move.l    A5,D0        */
  244.  
  245. #ifdef __cplusplus
  246. inline GlobalWorld GetGlobalWorld() {return __gLibraryManager->GetGlobalWorld();}
  247. inline GlobalWorld OpenGlobalWorld() {return SetCurrentGlobalWorld(GetGlobalWorld());}
  248. inline void    CloseGlobalWorld(GlobalWorld oldWorld) {SetCurrentGlobalWorld(oldWorld);}
  249. #else
  250. #define GetGlobalWorld()        (((void**)__gLibraryManager)[4])
  251. #define OpenGlobalWorld()        SetCurrentGlobalWorld(GetGlobalWorld())
  252. #define CloseGlobalWorld(world)    SetCurrentGlobalWorld(world)
  253. #endif
  254.  
  255. OSErr            InitGlobalWorld();        // called by standalone code only!!!
  256. void            FreeGlobalWorld();        // called by standalone code only!!!
  257.  
  258. #ifdef __cplusplus
  259. GlobalWorld        SetCurrentGlobalWorld(GlobalWorld newWorld);
  260. GlobalWorld        GetCurrentGlobalWorld();
  261.  
  262. GlobalWorld        GetGlobalWorld();
  263. GlobalWorld        OpenGlobalWorld();
  264. void            CloseGlobalWorld(GlobalWorld oldWorld);
  265. #endif
  266.  
  267. /**********************************************************************
  268. ** TLibraryFile "C" interface
  269. **
  270. ** The C interface to the TLibraryFile class defined in 
  271. ** LibraryManagerClasses.h. Used mainly to get resources out of a library.
  272. ***********************************************************************/
  273.  
  274. #ifdef __cplusplus
  275. extern "C" {
  276. class    TLibraryFile;
  277. #else
  278. typedef void TLibraryFile;
  279. #endif
  280.  
  281. TLibraryFile*        GetLocalLibraryFile();
  282.     
  283. OSErr    Preflight(TLibraryFile*, short* savedRefNum);
  284. OSErr    Postflight(TLibraryFile*, short savedRefNum);
  285.  
  286. Handle    GetSharedResource(TLibraryFile*, ResType theType, short theID);
  287. Handle    GetSharedIndResource(TLibraryFile*, ResType theType, short index);
  288. Handle    GetSharedNamedResource(TLibraryFile*, ResType theType, ConstStr255Param name);
  289.  
  290. void    ReleaseSharedResource(TLibraryFile*, Handle);
  291. long    CountSharedResources(TLibraryFile*, ResType theType);
  292.  
  293. size_t    GetSharedResourceUseCount(TLibraryFile*, Handle);
  294.  
  295. long    GetFileID(TLibraryFile*);
  296. long    GetRefNum(TLibraryFile*);
  297. short    GetVolumeRefNum(TLibraryFile*);
  298. OSErr    CloseLibrary(TLibraryFile*);
  299.  
  300. #ifdef __cplusplus
  301. }
  302. #endif
  303.  
  304. /*******************************************************************************
  305. ** Debugging Macros and inlines
  306. ********************************************************************************/
  307.  
  308. void DebugBreakProc(Boolean, const char*);
  309.  
  310. #ifdef __cplusplus
  311. };
  312.  
  313. inline void DoDebugBreak(Boolean value, const char* str)
  314. {
  315.     DebugBreakProc(value, str);
  316. }
  317.  
  318. inline void DoDebugBreak(const char* str)
  319. {
  320.     DebugBreakProc(true, str);
  321. }
  322.  
  323. #define ForceDebugBreak(str)        DoDebugBreak(true, str)
  324.  
  325. #if qDebug
  326.     #define DebugBreak(str)            DoDebugBreak(true, str)
  327.     #define DebugTest(val, str)        DoDebugBreak(val, str)
  328. #else
  329.     #define DebugBreak(str)
  330.     #define DebugTest(val, str)
  331. #endif
  332.  
  333. #else
  334.  
  335. #if qDebug
  336.     #define DebugBreak(str)            DebugBreakProc(true, str)
  337.     #define DebugTest(val, str)        DebugBreakProc(val, str)
  338. #else
  339.     #define DebugBreak(str)
  340.     #define DebugTest(val, str)
  341. #endif
  342.  
  343. #endif __cplusplus
  344.  
  345.  
  346. #endif